package de.imdb250junkie.utils;

import java.io.Serializable;
import java.net.URL;

/**
 * Class representing a movie from the imdb.
 * 
 * @author André Stannek
 * @version 2010-02-09
 */
public class Movie implements Serializable
{
    /**
     * 
     */
    private static final long serialVersionUID = 6477249637250745059L;

    /**
     * the titles of the movie.
     */
    private String originalTitle, localizedTitle;

    /**
     * the publishing year of the movie.
     */
    private int year;

    /**
     * the rank of the movie.
     */
    private int rank;

    /**
     * the "seen-state" by the user.
     */
    private State state;

    /**
     * the weblink to the imdb page of this movie.
     */
    private URL link;

    /**
     * the rating of this movie.
     */
    private float rating;

    /**
     * Default contructor. All values have to be indicated.
     */
    public Movie()
    {
        originalTitle = "";
        year = 1900;
        rank = -1;
        state = State.UNSEEN;
        rating = 0f;
    }

    /**
     * sets the original title of the movie.
     * 
     * @param title
     *            the title of the movie
     */
    public final void setOriginalTitle(final String title)
    {
        originalTitle = title;
    }

    /**
     * @return the title of the movie
     */
    public final String getOriginalTitle()
    {
        return originalTitle;
    }

    /**
     * Sets the publishing year of the movie.
     * 
     * @param year
     *            the publishing year
     */
    public final void setYear(final int year)
    {
        this.year = year;
    }

    /**
     * @return the publishing year
     */
    public final int getYear()
    {
        return year;
    }

    /**
     * sets the rank of the movie.
     * 
     * @param rank
     *            the rank
     */
    public final void setRank(final int rank)
    {
        this.rank = rank;
    }

    /**
     * @return the rank of the movie
     */
    public final int getRank()
    {
        return rank;
    }

    /**
     * Sets the IMDB URL of the movie.
     * 
     * @param url
     *            the URL
     */
    public final void setLink(final URL url)
    {
        link = url;
    }

    /**
     * @return the IMDB URL of the movie
     */
    public final URL getLink()
    {
        return link;
    }

    /**
     * Sets teh localized title of the movie.
     * 
     * @param localizedTitle
     *            teh localized title
     */
    public final void setLocalizedTitle(final String localizedTitle)
    {
        this.localizedTitle = localizedTitle;

    }

    /**
     * @return the localized title
     */
    public final String getLocalizedTitle()
    {
        return localizedTitle;
    }

    /**
     * Sets the state.
     * 
     * @param state
     *            the state
     */
    public final void setState(final State state)
    {
        this.state = state;
    }

    /**
     * @return the state
     */
    public final State getState()
    {
        return state;
    }

    /**
     * Sets the rating of the movie.
     * 
     * @param rating
     *            the rating
     */
    public final void setRating(final float rating)
    {
        this.rating = rating;
    }

    /**
     * @return the rating of the movie
     */
    public final float getRating()
    {
        return rating;
    }

    @Override
    public final String toString()
    {
        return rank + ": " + originalTitle + "/" + localizedTitle + " (" + year
                + ")";
    }

    @Override
    public final boolean equals(final Object obj)
    {
        if (obj instanceof Movie)
        {
            final Movie movie = (Movie) obj;
            return movie.getLink().toString().equals(link.toString());
        }
        else
        {
            return false;
        }
    }

    @Override
    public final int hashCode()
    {
        return link.toString().hashCode();
    }
}
